package com.jiangjiang.eshop.logistics.calculator;

import com.jiangjiang.eshop.logistics.constant.FreightTemplateType;
import com.jiangjiang.eshop.logistics.dto.FreightTemplateDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName FreightCalculatorFactory
 * @Description TODO
 * @Author jhw
 * @Date 2021/9/20 22:41
 * @Version 1.0
 **/
@Component
public class FreightCalculatorFactory {

    @Autowired
    private CustomRuleFreightCalculator customRuleFreightCalculator;
    @Autowired
    private DefaultLogisticsFreightCalculator defaultLogisticsFreightCalculator;
    @Autowired
    private FixedFreightCalculator fixedFreightCalculator;
    @Autowired
    private ReachFreeFreightCalculator reachFreeFreightCalculator;

    /**
     * 获取运费模板对应的运费计算器
     * @param freightTemplateDTO 运费模板
     * @return 运费计算器
     */
    public FreightCalculator get(FreightTemplateDTO freightTemplateDTO){

        if(FreightTemplateType.FIXED.equals(freightTemplateDTO.getType())){
            return fixedFreightCalculator;
        }else if(FreightTemplateType.REACH_FREE.equals(freightTemplateDTO.getType())){
            return reachFreeFreightCalculator;
        } else if(FreightTemplateType.CUSTOM_RULE.equals(freightTemplateDTO.getType())){
            return customRuleFreightCalculator;
        }else {
            return defaultLogisticsFreightCalculator;
        }
    }
}